/*
 * @Author: zf
 * @Date: 2022-11-30 12:15:48
 * @LastEditTime: 2022-11-30 15:58:00
 * @Description: 
 */
//axios 封装
import axios from "axios";
//创建axios实例
const service = axios.create({
    // baseURL: 'http://172.16.141.228:8081/admin',//接口地址
    baseURL: 'http://www.greatgump.top:8081/admin',//接口地址
    timeout: 5000,

    // headers: { "Content-Type": "multipart/form-data" }
    headers: {
        contentType: "application/json;charset=utf-8",
        dataType: 'json',
    }
})
//请求拦截
service.interceptors.request.use((config) => {
    config.headers = config.headers || {}
    if (localStorage.getItem('token')) {
        config.headers.token = localStorage.getItem('token') || ""
    }
    console.log(config);

    return config
})
//请求拦截
service.interceptors.request.use((config) => {
    config.headers = config.headers || {}
    if (localStorage.getItem('token')) {
        config.headers.token = localStorage.getItem('token') || ""
    }
    // console.log(config);

    return config
})
//响应拦截
service.interceptors.response.use((res) => {
    const code: number = res.data.code
    if (res.status == 200) {
        return res.data
    }
    return Promise.reject()//promise .reject请求失败

}, (err) => {
    console.log(err)
})
export default service;
